#include "two_player.h"
#include "ui_two_player.h"
#include "widget.h"
#include <QMessageBox>
Two_Player::Two_Player(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Two_Player)
{
    ui->setupUi(this);
}

Two_Player::~Two_Player()
{
    delete ui;
}

void Two_Player::Init_Game_dou()
{
    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Col;j++)
        {
            Game_Area_dou[i][j]=0;
        }
    }
    Down_Time_dou=800;
    Refresh_Time_dou=30;
    //以上数据定义见Two_player.h

    //初始化随机数种子
    srand(time(0));

    //分数清零
    score_dou=0;

    //运行游戏
    Start_Game_dou();
}

void Two_Player::Start_Game_dou()
{
    Game_Timer_dou=startTimer(Down_Time_dou);
    //开始游戏计时
    Paint_Timer_dou=startTimer(Refresh_Time_dou);
    //开启界面刷新计时器
    //产生初始下一个方块
    //int Block_ID=rand()%7;
    //Block_Crate(Next_Block, Block_ID);
    //Block_Reset();
}

void Two_Player::Game_Over_dou()
{
    //结束后停止计时器
    killTimer(Game_Timer_dou);
    killTimer(Paint_Timer_dou);
    QMessageBox::information(this,"failed","game over");
    is_Over_dou = true;
}

void Two_Player::closeEvent(QCloseEvent *event)
{
    Game_Over_dou();
    emit close_dou();
}

bool Two_Player::isOver_dou()
{
    return is_Over_dou;
}
